package com.jthinker.bean.vo;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * Created by chen.gang on 15-2-23.
 */
public class QueryResult<T> implements Serializable
{
    private final int total;
    private final List<T> data;
    private final int page;
    private final int pageCount;
    private final int pageSize;

    public static final QueryResult EMPTY_RESULT = new QueryResult(0, Collections.emptyList(), 1, 10);

    public static <T> QueryResult<T> empty()
    {
        return (QueryResult<T>) EMPTY_RESULT;
    }

    public QueryResult(int total, List<T> data, int page, int pageSize)
    {
        this.total = total;
        this.data = data;
        this.page = page;
        this.pageSize = pageSize;
        this.pageCount = total / pageSize + (total % pageSize == 0 ? 0 : 1);
    }

    public int getPage()
    {
        return page;
    }

    public int getTotal()
    {
        return total;
    }

    public List<T> getData()
    {
        return data;
    }

    public int getPageCount()
    {
        return pageCount;
    }

    public int getPageSize()
    {
        return pageSize;
    }
}
